
namespace DrawToolsLib {
    /// <summary>
    /// Add new object command
    /// </summary>
    class CommandAdd : CommandBase {
        private GraphicsBase newObject;

        /// <summary>
        /// Create this command with DrawObject instance added to the list
        /// </summary>
        public CommandAdd(GraphicsBase newObject)
            : base() {
            // Keep ref of added object
            this.newObject = newObject;
        }

        /// <summary>
        /// Delete added object
        /// </summary>
        public override void Undo(DrawingCanvas drawingCanvas) {
            drawingCanvas.Pop(newObject);
            HelperFunctions.UnselectAll(drawingCanvas);
        }

        /// <summary>
        /// Add object again
        /// </summary>
        public override void Redo(DrawingCanvas drawingCanvas) {
            HelperFunctions.UnselectAll(drawingCanvas);

            drawingCanvas.Push(newObject);
            HelperFunctions.UnselectAll(drawingCanvas);
            newObject.IsSelected = true;
        }
    }
}
